import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import * as db from '@/util/db.js'
let userInfo = db.get('userInfo') || {}
let token = db.get('token') || ""
const store = new Vuex.Store({
	state: {
		userInfo: userInfo,
		token: token,
		regionList: [],
		order: {}
	},
	getters: {
		getUserInfoData: state => state.userInfo,
		getTokenData: state => state.token,
		getRegionListData: state => state.regionList,
		getOrderData: state => state.order,
	},
	mutations: {
		setUserInfoData(state, data) {
			state.userInfo = data
			db.set('userInfo', state.userInfo)
		},
		setTokenData(state, data) {
			state.token = data
			db.set('token', state.token)
		},
		setRegionListData(state, data) {
			state.regionList = data
		},
		setRegionState(state, {
			regionId,
			regionState
		}) {
			state.regionList.find((item) => item.regionId == regionId).regionState = regionState
		},
		setOrderData(state, data) {
			state.order = data
		},
	}
})

export default store
